package reproductores;

import java.io.IOException;

public class Rhythmbox {

	public static void encolar(boolean solamenteEncolar, boolean unSoloTema, String url, String primerTema) {
		System.out.println("Entro");
		
		if (solamenteEncolar) {
			
			if (unSoloTema) {
				String[] commandLin = new String[]{"bash", "-c","rhythmbox-client " + "\"" + url + "\""};
				
				try {
					//System.out.println(commandLin[0] + " " + commandLin[1]);
					@SuppressWarnings("unused")
					Process procesoLin;
					procesoLin = Runtime.getRuntime().exec(commandLin, null, null);
				}
				catch (Exception e) {
					e.printStackTrace();
				}
			}
			else {
				   String[] commandLin = {"bash", "-c", "rhythmbox-client " + url};
				   //System.out.println(commandLin[0] + " " + commandLin[1] + " " + commandLin[2]);
				   try {
					Runtime.getRuntime().exec(commandLin);
				} catch (IOException e) {
					e.printStackTrace();
				} 
			}
		}
		else {
			
			if (unSoloTema) {
				//No funciona
				//
				//Si lo ejecuto desde consola de la forma: rhythmbox-client --play "/media/datosWin/Backup Lea/Victor/05 - In The Wee Small Hours Of The Morning.mp3"
				//me la agrega a la lista pero no lo playea
				//Si lo ejecuto desde consola de la forma: bash -c rhythmbox-client --play "/media/datosWin/Backup Lea/Victor/05 - In The Wee Small Hours Of The Morning.mp3"
				//no me lo agrega

				String[] commandLin = new String[]{"bash", "-c" ,"rhythmbox-client", "--play" , "\"" + url + "\""};
				try {
					//System.out.println(commandLin[0] + " " + commandLin[1] + " " + commandLin[2] + " " + commandLin[3] + " " + commandLin[4]);
					@SuppressWarnings("unused")
					Process procesoLin;
					procesoLin = Runtime.getRuntime().exec(commandLin, null, null);
				}
				catch (Exception e) {
					e.printStackTrace();
				}
			}
			else {
				//No funciona
				//
				//Me lo agrega pero no playea
				
				   String[] commandLin = {"bash", "-c", "rhythmbox-client --play " + url};
				   //System.out.println(commandLin[0] + " " + commandLin[1] + " " + commandLin[2]);
				   try {
					Runtime.getRuntime().exec(commandLin);
				} catch (IOException e) {
					e.printStackTrace();
				} 
			}
		}
	}
	
	public static void playPause() {
		String[] commandLin = {"bash", "-c", "rhythmbox-client --play-pause"};
		try {
			Runtime.getRuntime().exec(commandLin);
		} catch (IOException e) {
			e.printStackTrace();
		} 
	}
	
	public static void stop() {
		String[] commandLin = {"bash", "-c", "rhythmbox-client --play-pause"};
		try {
			Runtime.getRuntime().exec(commandLin);
		} catch (IOException e) {
			e.printStackTrace();
		} 
	}
	
	public static void limpiarLista() {
		String[] commandLin = {"bash", "-c", "rhythmbox-client --clear-queue"};
		try {
			Runtime.getRuntime().exec(commandLin);
		} catch (IOException e) {
			e.printStackTrace();
		} 
	}
}
